<?php
// +----------------------------------------------------------------------
// | KITEGO-Admin「开箱即用」「人人全栈」
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2024 https://www.kitego.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed KITEGO并不是自由软件，未经许可不能去掉KITEGO相关版权
// +----------------------------------------------------------------------
// | Author: KITEGO Team <bd@kitego.cn>
// +----------------------------------------------------------------------

namespace app\adminapi\services\setting;

use app\common\services\TranslationService;

class ToolService
{
    /**
     * 强制刷新缓存
     */
    public function refreshCache()
    {
        // 管理员信息
        $adminInfo = [
            'adminRole' => request()->adminRole,
            'userId' => request()->userId,
            'nickname' => request()->nickname,
            'avatar' => request()->avatar,
        ];

        // 菜单
        $res = app()->make(SystemMenuService::class)->getSystemMenu()->getData();
        $menu = $res['data']['menu'];
        $permissions = $res['data']['permissions'];
        $dashboardGrid = $res['data']['dashboardGrid'];

        // 语言包
        $res = app()->make(TranslationService::class)->listTranslationJson()->getData();
        $langFlag = $res['data']['langFlag'];
        $langTranslation = $res['data']['langTranslation'];

        return success([
            'adminInfo' => $adminInfo,
            'menu' => $menu ?? [],
            'permissions' => $permissions ?? [],
            'dashboardGrid' => $dashboardGrid ?? [],
            'langFlag' => $langFlag,
            'langTranslation' => $langTranslation,
        ]);
    }
}